#Include "src/message.bas"
#include "src/sock.bi"

Function BotMain Alias "BotMain" ( rawmsg As String ) As message Export

Dim as message n
Dim as integer totalplugins
Dim as IRC.message myMessage

dim as string text
dim as string newsflag

myMessage.parse( rawmsg )

dim as string temp=myMessage.param (myMessage.trailing)

newsflag = right(lcase(temp), (len(temp)-6))

if left(lcase(temp), 5) = "^news" then
    
    if newsflag = "top" or newsflag = "" or len(lcase(temp)) = 5 then
        text = "Top Stories: http://news.google.com/nwshp?oe=UTF-8&tab=wn&ned=us"

    elseif newsflag  = "world" or newsflag = "w" then
        text = "World News: http://news.google.com/nwshp?oe=UTF-8&tab=wn&ned=us&topic=w"

    elseif newsflag  = "us" then
        text = "Top US Stories: http://news.google.com/nwshp?oe=UTF-8&tab=wn&ned=us&topic=n"

    elseif newsflag  = "business" or newsflag = "b" then
        text = "Business News: http://news.google.com/nwshp?oe=UTF-8&tab=wn&ned=us&topic=b"

    elseif newsflag  = "science" or newsflag = "technology" or newsflag = "st" then
        text = "Science & Technology News: http://news.google.com/nwshp?oe=UTF-8&tab=wn&ned=us&topic=t"

    elseif newsflag  = "sport" or newsflag = "s" then
        text = "Sports Updates: http://news.google.com/nwshp?oe=UTF-8&tab=wn&ned=us&topic=s"

    elseif newsflag  = "entertainment" or newsflag = "e" then
        text = "Entertainment Stories: http://news.google.com/nwshp?oe=UTF-8&tab=wn&ned=us&topic=e"

    elseif newsflag  = "health" or newsflag = "h" then
        text = "Health News: http://news.google.com/nwshp?oe=UTF-8&tab=wn&ned=us&topic=m"

    elseif newsflag  = "popular" or newsflag = "p" then
        text = "Popular Stories: http://news.google.com/nwshp?oe=UTF-8&tab=wn&ned=us&topic=po"
    
    elseif newsflag = "help" or newsflag = "?" then
        text = "^news ( top | world/w | us | business/b | science/technology/st | sport/s | entertainment/e | health/h | popular/p ). Version 0.1b. News plugin written by King_anarky. Sourced from Google News."
    
    else
        text = "Invalid news parameter. Type ^news help or ^news ?"
        
    endif
    
    n.dest=myMessage.param(0)
    n.msg = text
    n.msgtype=1
endif

Return n
End Function
